package org.argus.job.server.system.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.argus.common.core.domain.R;
import org.argus.job.server.system.domain.AppInfo;
import org.argus.job.server.system.management.model.AppInfoPageReq;
import org.argus.job.server.system.management.service.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 刘文/Cliff Liu
 * @Date 2024/7/16
 */
@Api("接入应用信息管理")
@RestController
@RequestMapping("/app-info/v1/app-info")
public class AppInfoController {

    @Autowired
    private AppInfoService service;

    @ApiOperation("获取应用列表")
    @GetMapping("/page")
    public R<Page<AppInfo>> page(Page page, AppInfoPageReq pageReq) {
        return R.ok(service.page(page, pageReq));
    }

    @ApiOperation("新增应用接入信息")
    @PostMapping
    public R<Void> add(@RequestBody AppInfo appInfo) {
        service.add(appInfo);
        return R.ok();
    }

    @ApiOperation("修改应用接入信息")
    @PutMapping
    public R<Void> update(@RequestBody AppInfo appInfo) {
        service.update(appInfo);
        return R.ok();
    }

    @ApiOperation("修改应用状态")
    @PutMapping("/status")
    public R<Void> updateStatus(@RequestBody AppInfo appInfo) {
        service.updateStatus(appInfo);
        return R.ok();
    }

    @ApiOperation("设置新的app 接入secret")
    @PutMapping("/reset-secret/{id}")
    public R<Void> resetSecret(@PathVariable("id") Long id) {
        service.resetSecret(id);
        return R.ok();
    }

    @ApiOperation("获取应用列表")
    @GetMapping("/list")
    public R<List<AppInfo>> list() {
        return R.ok(service.list());
    }
}
